package com.ruoyi.account.service.impl;

import java.util.List;
import java.util.Map;

import com.ruoyi.account.enums.WeiXinUserIdEnum;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.db.mapper.AccountInfoMapper;
import com.ruoyi.db.domain.AccountInfo;
import com.ruoyi.account.service.IAccountInfoService;
import com.ruoyi.common.core.text.Convert;

/**
 * 总账号信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-02-02
 */
@Service
@DataSource(DataSourceType.SLAVE)
public class AccountInfoServiceImpl implements IAccountInfoService 
{
    @Autowired
    private AccountInfoMapper accountInfoMapper;

    /**
     * 查询总账号信息
     * 
     * @param id 总账号信息主键
     * @return 总账号信息
     */
    @Override
    public AccountInfo selectAccountInfoById(Long id)
    {
        return accountInfoMapper.selectAccountInfoById(id);
    }

    /**
     * 查询总账号信息列表
     * 
     * @param accountInfo 总账号信息
     * @return 总账号信息
     */
    @Override
    public List<AccountInfo> selectAccountInfoList(AccountInfo accountInfo)
    {
        return accountInfoMapper.selectAccountInfoList(accountInfo);
    }

    /**
     * 查询总账号信息列表
     *
     * @param accountInfo 总账号信息
     * @return 总账号信息
     */
    @Override
    public List<Map<String, Object>> selectAccountInfoListMap(AccountInfo accountInfo)
    {
        return accountInfoMapper.selectAccountInfoListMap(accountInfo);
    }

    @Override
    public Map<String, Object> selectAccountInfoAllListMap(AccountInfo accountInfo)
    {
        return accountInfoMapper.selectAccountInfoAllListMap(accountInfo);
    }

    /**
     * 新增总账号信息
     * 
     * @param accountInfo 总账号信息
     * @return 结果
     */
    @Override
    public int insertAccountInfo(AccountInfo accountInfo)
    {

        String weixinUserid = accountInfo.getWeixinUserid();
        WeiXinUserIdEnum entityByValue = WeiXinUserIdEnum.getEntityByValue(Integer.valueOf(weixinUserid));
        accountInfo.setWeixinUserid(entityByValue.getValue());
        accountInfo.setOwnerId(entityByValue.getId());
        accountInfo.setOwnerName(entityByValue.getName());


        accountInfo.setCreateTime(DateUtils.getNowDate());
        return accountInfoMapper.insertAccountInfo(accountInfo);
    }

    /**
     * 修改总账号信息
     * 
     * @param accountInfo 总账号信息
     * @return 结果
     */
    @Override
    public int updateAccountInfo(AccountInfo accountInfo)
    {
        String weixinUserid = accountInfo.getWeixinUserid();
        WeiXinUserIdEnum entityByValue = WeiXinUserIdEnum.getEntityByValue(Integer.valueOf(weixinUserid));
        accountInfo.setWeixinUserid(entityByValue.getValue());
        accountInfo.setOwnerId(entityByValue.getId());
        accountInfo.setOwnerName(entityByValue.getName());

        accountInfo.setUpdateTime(DateUtils.getNowDate());
        return accountInfoMapper.updateAccountInfo(accountInfo);
    }

    /**
     * 批量删除总账号信息
     * 
     * @param ids 需要删除的总账号信息主键
     * @return 结果
     */
    @Override
    public int deleteAccountInfoByIds(String ids)
    {
        return accountInfoMapper.deleteAccountInfoByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除总账号信息信息
     * 
     * @param id 总账号信息主键
     * @return 结果
     */
    @Override
    public int deleteAccountInfoById(Long id)
    {
        return accountInfoMapper.deleteAccountInfoById(id);
    }

    @Override
    public List<Map<String, Object>> listAllMap() {
        return accountInfoMapper.listAllMap();
    }
}
